<template>
  <div>
    <div class="title-box">
      <div>用户登录</div>
    </div>

    <el-form ref="postForm" :model="postForm" :rules="loginRules">

      <el-form-item prop="realName">
        <el-input
          v-model="postForm.realName"
          style="width: 100%"
          placeholder="姓名"
          prefix-icon="el-icon-user"
        />
      </el-form-item>
      <el-form-item prop="userName">
        <el-input
          v-model="postForm.userName"
          style="width: 100%"
          placeholder="手机号"
          prefix-icon="el-icon-mobile"
        />
      </el-form-item>

      <el-form-item prop="companyName">
        <el-input v-model="postForm.companyName" placeholder="科室/中队">
          <template #prefix>
            <i slot="prefix-icon" class="iconfont icon-gongsi" />
          </template>
        </el-input>
      </el-form-item>
      <!-- <el-form-item prop="password">
        <el-input
          v-model="postForm.password"
          show-password
          style="width: 100%"
          placeholder="密码"
          type="password"
          prefix-icon="el-icon-lock"
        />
      </el-form-item> -->

      <el-form-item>
        <el-button
          :loading="loading"
          type="primary"
          style="width: 100%; background-color: #ff0f31; border-color: #ff0f31"
          @click.native.prevent="handleReg"
        >登录</el-button
        >
      </el-form-item>
    </el-form>

    <!-- <div style="display: flex; align-items: center; justify-content: flex-end">
      <el-link type="danger" href="/#/login">已有账号</el-link>
    </div> -->
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      postForm: {
        userName: '',
        realName: '',
        password: '',
        companyName: ''
      },
      loginRules: {
        password: [
          { required: true, trigger: 'blur', message: '登录密码不能为空！' }
        ],
        userName: [
          { required: true, trigger: 'blur', message: '手机号不能为空！' }
        ],
        realName: [
          { required: true, trigger: 'blur', message: '姓名不能为空！' }
        ],
        companyName: [
          { required: true, trigger: 'blur', message: '科室/中队不能为空！' }
        ],
        captchaValue: [
          { required: true, trigger: 'blur', message: '验证码不能为空' }
        ]
      },
      loading: false
    }
  },
  computed: {
    ...mapGetters(['siteData'])
  },

  methods: {
    handleReg() {
      console.log(this.postForm)
      const obj = {
        userName: this.postForm.userName,
        realName: this.postForm.realName,
        password: '123456',
        companyName: this.postForm.companyName
      }

      this.$refs.postForm.validate((valid) => {
        if (valid) {
          this.loading = true
          this.$store
            .dispatch('user/reg', obj)
            .then(() => {
              this.$router.push({ path: this.redirect || '/admin/dashboard' })
              this.loading = false
            })
            .catch(() => {
              this.loading = false
            })
        }
      })
    }
  }
}
</script>

<style>
.icon-gongsi {
  width: 25px;
  height: 36px;
  line-height: 36px;
  display: inline-block;
}
.title-box div {
  color: #ff0f31;
  border-bottom: #ff0f31 2px solid;
}
</style>
